package main

import (
	"gfrest/common/export"
	_ "gfrest/cron"
	_ "gfrest/web/boot"
	_ "gfrest/web/router"

	"os"
	"os/signal"
	"syscall"

	"github.com/getsentry/sentry-go"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/glog"
	"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
	Use:   "",
	Short: "",
	Long:  `cloud db ops server`,
	Run: func(cmd *cobra.Command, args []string) {
		startServer()
	},
}

var exportCmd = &cobra.Command{
	Use:   "export",
	Short: "export",
	Long:  `export db config`,
	Run: func(cmd *cobra.Command, args []string) {
		export.ExportConfigEnvFile()
	},
}

// Execute Execute
func Execute() {
	rootCmd.AddCommand(exportCmd)
	if err := rootCmd.Execute(); err != nil {
		glog.Info(err)
		os.Exit(1)
	}
}

func startServer() {

	stop := make(chan os.Signal, 1)

	signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)

	go runServer()
	// log.Info(context.Background(), "server starting...")

	select {
	case <-stop:
		// export.Clean()
		return
	}
}
func runServer() {
	defer sentry.Recover()

	g.Server().Run()

}

// @title 测试服务
// @version 1.0
// @description This is a sample server

// @BasePath /

// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization

func main() {
	Execute()
}
